import React from 'react';
import { WeaFormItem, WeaLocaleProvider } from 'ecCom';
import { WeaSwitch } from 'comsMobx';
import { Modal } from 'antd';

const getLabel = WeaLocaleProvider.getLabel;

export const RenderForm = (
  form,
  field,
  config,
  renderItem,
  switchConfig,
  replaceSwitch,
) => {
  const preCls = 'email-form';
  return (
    <WeaFormItem
      ecId={`${
        (this && this.props && this.props.ecId) || ''
      }_WeaFormItem@udq6h5`}
      label={`${getLabel(field.labelID, field.label)}`}
      labelCol={{ span: `${field.labelcol}` }}
      wrapperCol={{ span: `${field.fieldcol}` }}
      className={`${preCls}-formItem ${field.domkey[0]}`}
      error={form.getError(field)}
      tipPosition="bottom"
      {...config}
    >
      {replaceSwitch || (
        <WeaSwitch
          ecId={`${
            (this && this.props && this.props.ecId) || ''
          }_WeaSwitch@yo9mtz`}
          fieldConfig={field}
          form={form}
          {...switchConfig}
        />
      )}
      {renderItem}
    </WeaFormItem>
  );
};

export const AntdConfirm = (config, okFun) => {
  Modal.confirm({
    title: getLabel(131329, '信息确认'),
    content: getLabel(15097, '确定要删除吗?'),
    okText: getLabel(826, '确定'),
    cancelText: getLabel(31129, '取消'),
    onOk: okFun,
    ...config,
  });
};
